<?php
$path =  str_replace('/wp-content/plugins/stSocialMediaToolbox/Toolboxes/stPublishToolbox/cronjob','',dirname(__FILE__));
require($path.'/wp-config.php');
require_once($path.'/wp-content/plugins/stSocialMediaToolbox/Toolboxes/stFlickrToolbox/libs/stFlickrToolboxclass.php');
global $wpdb;
$data['cronjob_name']  = 'cronjob Flickr Publish';
$data['toolbox_name'] = 'stPublishToolbox';
$data['url'] = dirname(__FILE__).'/flickr_publish.php';
$data['status'] = 0;
$data['ctime'] = date_i18n('Y-m-d H:i:S');
$wpdb->insert('wp_st_cronjob_log',$data);
$log_id = $wpdb->get_var("SELECT MAX(id) FROM wp_st_cronjob_log");
$flickr_option = array(
                    'flickr_key' => '1f8711876db0c6f31cf443f1bc75764e',
                    'flickr_secret' => '6846a902b08503f4',
                    'flickr_user_id' => '34084469@N07',
                    'flickr_token' => '72157627219993930-5df0528b6f2ae63e'
                );
$flickr_config = array (
                    'default_flickr_key' => 'f8aa364069fdcf9c3df3bf0e4650ae30',
                    'default_flickr_secret' => 'eb0b402f3ddf8b9d',
                    'default_flickr_token' => '72157625463576546-4c1ea11aaf1c3563',
                    'default_flickr_user_id' => '53713111@N03',
                );
$flickr = new stFlickrToolboxclass($flickr_config,$flickr_option);
foreach($wpdb->get_results("SELECT * FROM st_publishing WHERE published=1 AND publish_type='flickr'") as $row){
    $date_array = explode(' ',$row->time);
    $date = explode('-',$date_array[0]);
    $time = explode(':',$date_array[1]);
    $current =  mktime ($time[0],$time[1],00 ,intval($date[1]) ,intval($date[0]) ,$date[2] );
    if($current <= mktime(date_i18n("H"),date_i18n("i"),date_i18n("s"),date_i18n("n"),date_i18n("j"),date_i18n("Y"))){
       
                      $flickr->flickr->sync_upload($row->image_upload,$row->name,$row->content,'SMT',1);
                      $wpdb->update('st_publishing',array('published'=>0),array('id'=>$row->id));
    }
}
$wpdb->update('wp_st_cronjob_log',array('status'=>1),array('id'=>$log_id));

?>
